
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.event.KeyEvent;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.powerbot.core.bot.Bot;
import org.powerbot.core.bot.handlers.ScriptHandler;
import org.powerbot.core.event.listeners.PaintListener;
import org.powerbot.core.script.ActiveScript;
import org.powerbot.core.script.job.Task;
import org.powerbot.core.script.job.state.Node;
import org.powerbot.core.script.job.state.Tree;
import org.powerbot.game.api.Manifest;
import org.powerbot.game.api.methods.Game;
import org.powerbot.game.api.methods.Settings;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Keyboard;
import org.powerbot.game.api.methods.interactive.NPCs;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.methods.widget.Bank;
import org.powerbot.game.api.methods.widget.Camera;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Timer;
import org.powerbot.game.api.wrappers.interactive.NPC;
import org.powerbot.game.api.wrappers.interactive.Player;
import org.powerbot.game.api.wrappers.widget.WidgetChild;

@Manifest(authors = { "roidskiz" }, name = "FireKiller", version = 1.0)
public class Fisher extends ActiveScript implements PaintListener
{
	public static String user = "chrisshart11@hotmail.com",//"chrisshart11@hotmail.com",
			pass = "n1mbus123";
	
	private Tree container = null;
	private List<Node> jobs = new ArrayList<Node>();
	public static boolean dropping = false,banking = false,cooking = false;
	public Timer runTime;
	public int atkStart;
	public boolean camSetup = false;
	public boolean guiIsUp = false;
	@Override
	public int loop() {
		try
		{
			
				if(atkStart == 0)
					atkStart = Settings.get(93);
				if(Inventory.isFull())
				{
					for(NPC n : NPCs.getLoaded(496))
						if(n.getName().contains("bank"))
							banking = true;
					if(!banking)
						dropping = true;
				}
	
				if(container !=null) 
		        {
					final Node job = container.state();
					if(job != null)
					{
						container.set(job);
						getContainer().submit(job);
						job.join();
					}
		        }
		        else
		        {
		        	provide( new LoginManager(),new Fish(),new Drop(),new EOCFixer());
		        }
			
		}
		catch(Exception ex)
		{
			System.out.println("error");
		}
        return Random.nextInt(100, 300);
	}
	
	public final void provide(final Node... j) 
	{
		for (final Node job : j) 
		{
			if(!jobs.contains(job)) 
			{
				jobs.add(job);
			}
		}
		container = new Tree(jobs.toArray(new Node[jobs.size()]));
	}

	public void onStart()
	{
		LoginManager.Set(user, pass);
		runTime = new Timer(0);
	}
	public void onStop()
	{
		runTime = null;
	}
	@Override
	public void onRepaint(Graphics arg0) {
		Graphics2D g = (Graphics2D) arg0;
		g.setColor(Color.cyan);
		
		Player p = Players.getLocal();
		g.drawString("bank = "+banking +" drop = "+dropping ,5,270);
		g.drawString("User = "+LoginManager.user +" Pass = "+LoginManager.pass+ " login status: "+LoginManager.status,5,280);
		g.drawString("Fishing Exp : " + ((Settings.get(93) - atkStart)/10), 5, 290);
		if(runTime!=null)
		{
			g.drawString("Time Running:"+ runTime.toElapsedString(), 5, 300);
			int xpGained = (Settings.get(93) - atkStart);
			g.drawString("xp Hour:"+ (xpGained * ( ((60*60*1000)/10) / runTime.getElapsed())), 5, 310);
		}
		if(Fish.clickedSpot!= null)
		{
			for(Polygon poly : Fish.clickedSpot)
			{
				g.drawPolygon(poly);
			}
		}
		
		//
		//1hour 
		//total exp
		//time taken
		//(1hour / time taken) * total exp
	}
}
